package org.example.everyday;

import java.util.Arrays;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/5/25 0025 10:50
 */
public class Lc467 {
    public static void main(String[] args) {
        Lc467 lc467 = new Lc467();

        String p = "zab";
        int res = lc467.findSubstringInWraproundString(p);
        System.out.println(res);
    }
    public int findSubstringInWraproundString(String p) {
        int[] dp = new int[26];
        int k = 0;
        for (int i = 0; i < p.length(); i++) {
            // 字符之差为 1 或 -25
            if(i > 0 && (p.charAt(i) - p.charAt(i - 1) + 26) % 26 == 1){
                ++k;
            } else {
                k = 1;
            }
            dp[p.charAt(i) - 'a'] = Math.max(dp[p.charAt(i) - 'a'],k);
        }

        return Arrays.stream(dp).sum();
    }
}
